package com.longsichao.lscframe.app;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Set;

public class LSCConfig {

    private final String CONFIG_FILE_NAME;
    private Context context;

    protected LSCConfig(Context context) {
        this.context = context.getApplicationContext();
        CONFIG_FILE_NAME = "LSCConfig_" + getClass().getSimpleName();
    }

    protected SharedPreferences getSP() {
        return context.getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_MULTI_PROCESS);
    }

    protected SharedPreferences.Editor getSPE() {
        return getSP().edit();
    }

    protected void saveBoolean(String key, boolean value) {
        SharedPreferences.Editor e = getSPE();
        e.putBoolean(key, value);
        e.commit();
    }

    protected void saveFloat(String key, float value) {
        SharedPreferences.Editor e = getSPE();
        e.putFloat(key, value);
        e.commit();
    }

    protected void saveInt(String key, int value) {
        SharedPreferences.Editor e = getSPE();
        e.putInt(key, value);
        e.commit();
    }

    protected void saveLong(String key, long value) {
        SharedPreferences.Editor e = getSPE();
        e.putLong(key, value);
        e.commit();
    }

    protected void saveString(String key, String value) {
        SharedPreferences.Editor e = getSPE();
        e.putString(key, value);
        e.commit();
    }

    protected void saveStringSet(String key, Set<String> value) {
        SharedPreferences.Editor e = getSPE();
        e.putStringSet(key, value);
        e.commit();
    }

    protected void remove(String key) {
        SharedPreferences.Editor e = getSPE();
        e.remove(key);
        e.commit();
    }

    protected void clear() {
        SharedPreferences.Editor e = getSPE();
        e.clear();
        e.commit();
    }


}
